#include <iostream>
#include <vector>

using namespace std;
class Solution
{
public:
    string reversePrefix(string word, char ch)
    {
        int position = -1;
        if (word.find_first_of(ch) != string::npos)
        {
            position = word.find_first_of(ch);
        }
        cout << position << endl;
        auto reversedString = [](string str) -> string
        {
            string s = "";
            for (int i = str.length() - 1; i >= 0; i--)
            {
                s += str[i];
            }
            return s;
        };

        return position == -1 ? word : reversedString(word.substr(0, position + 1)) + word.substr(position + 1);
    }

    string reversePrefix_2(string word, char ch)
    {
        int index = word.find(ch);
        if (index != string::npos)
        {
            reverse(word.begin(), word.begin() + index + 1);
        }
        return word;
    }
};
int main()
{
    Solution s;
    cout << s.reversePrefix("abcdefd", 'd') << endl;
    system("pause");
    return 0;
}
